package chapter_22_state.classic.context;

import chapter_22_state.classic.state.ConcreateState1;
import chapter_22_state.classic.state.ConcreateState2;
import chapter_22_state.classic.state.State;

/**
 * Created by yao on 2016/10/11.
 * 环境角色；
 */
public class Context {

    //持有一个State类型的对象实例
    private State currentState;

    public static final State STATE1 = new ConcreateState1();
    public static final State STATE2 = new ConcreateState2();

    public State getCurrentState() {
        return currentState;
    }

    public void setCurrentState(State currentState) {
        this.currentState = currentState;

        /**切换状态**/
        this.currentState.setContext(this);
    }

    public void handle1(String param){
        this.currentState.handle1(param);
    }

    public void handle2(String param){
        this.currentState.handle2(param);
    }

}
